package easyOrm.test;

import java.util.HashMap;
import java.util.Map;

import com.lingyuting.orm.ActiveRecord;

public class User extends ActiveRecord<User> {

    // 非必须覆盖方法，如果自己定义了数据的连接则该字符串为该类的路径
    @Override
    public String connectionClass() {
        return "com.lingyuting.orm.DbManager";
    }

    @Override
    public String getTable() {
        return "user";
    }

    public ActiveRecord<User> getInstance() {
        return new User();
    }

    public static void main(String[] args) {
        User u = new User();
        u.setAttribute("nick", "easyOrm");
        u.save();
        System.out.println(u.getAttribute("id"));
        // 其它方法
        u.findByPk("3");
        u.find("nick = ?", "easyOrm");
        u.findAll();
        u.findAll("id > ?", 1);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("nick", "bennett");
        u.updateByPk("1", data);
        u.updateAll(change, sql, params);//暂未实现
        User model = new User();
        u = model.findByPk("1");
        u.setAttribute("nick", "cccc");
        u.update();//or u.save();
    }
}
